<template>
  <div class="member-info">
    <el-form label-width="90px"
      ref="form"
      :model="form"
      :rules="rules">
      <el-row>
        <el-col :span="12">
          <div class="input-wrap"
            style="margin-top:10px">
            <el-form-item label="ID">
              <el-input v-model="form.id"
                disabled></el-input>
            </el-form-item>
          </div>
          <div class="input-wrap">
            <el-form-item label="姓名">
              <el-input v-model="form.name"
                disabled></el-input>
            </el-form-item>
          </div>
          <div class="input-wrap">
            <el-form-item label="手机号码">
              <el-input v-model="form.phone"
                disabled></el-input>
            </el-form-item>
          </div>
          <div class="input-wrap">
            <el-form-item label="出生日期">
              <el-date-picker type="date"
                placeholder="选择日期"
                v-model="form.birthday"
                style="width: 100%;"
                value-format="yyyy-MM-dd"
                disabled></el-date-picker>
            </el-form-item>
          </div>
          <div class="input-wrap">
            <el-form-item label="注册时间">
              <el-date-picker type="datetime"
                placeholder="选择日期"
                v-model="form.createTime"
                style="width: 100%;"
                disabled></el-date-picker>
            </el-form-item>
          </div>
        
        </el-col>
        <el-col :span="12">
          <div class="input-wrap"
            style="margin-top:10px">
            <el-form-item label="登录名">
              <el-input v-model="form.nickName"
                disabled></el-input>
            </el-form-item>
          </div>
          <div class="input-wrap">
            <el-form-item label="邮箱">
              <el-input v-model="form.email"
                disabled></el-input>
            </el-form-item>
          </div>
          <div class="input-wrap">
            <el-form-item label="性别">
              <el-select v-model="form.sex"
                placeholder="请选择性别"
                disabled>
                <el-option label="男"
                  value="1"></el-option>
                <el-option label="女"
                  value="2"></el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="input-wrap">
            <el-form-item label="客户来源">
              <el-select v-model="form.parentId"
                placeholder="请选择客户来源" disabled>
                <el-option v-for="item in sourceList"
                  :key="item.id"
                  :label="item.platform"
                  :value="item.id"></el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="input-wrap">
            <el-form-item label="钱包余额">
              <el-input v-model="form.haokeCoin" disabled></el-input>
            </el-form-item>
          </div>
          
        </el-col>
      </el-row>
    </el-form>
    <div class="information-btn">
      <el-form-item>
        <el-button @click="back">返回</el-button>
      </el-form-item>
    </div>
  </div>
</template>
<script>
const Breadcrumb = () => import("@/components/common/Breadcrumb");
import { queryMemberById, updateMember } from "@/public/js/member";

export default {
  token: "",
  data() {
    return {
      form: {},
      id: "",
      rules: {
        name: [{ required: true, message: "请输入会员姓名" }],
        startTime: [{ required: true, message: "请选择开始日期" }],
        phone: [
          {
            required: true,
            message: "请输入手机号码"
          }
        ],
        createTime: [{ required: true, message: "请选择注册时间" }],
        account: [{ required: true, message: "请输入会员登录名" }],
        email: [{ required: true, message: "请输入邮箱" }],
        sex: [{ required: true, message: "请选择性别" }],
        birthday: [{ required: true, message: "请填写生日" }],
        number: [
          { required: true, message: "请填写数量" },
          { type: "number", message: "请填写正整数" }
        ]
      },
      platformList: [],
      hobbyInterest: [],
      hobbyRepast: [],
      hobbyInterestIcon: "",
      hobbyRepastIcon: "",
      editIcon: "",
      dialogEdit: false,
      witchHobby: true,
      witchIndex: "",
      channelList: [],
      sourceList: []
    };
  },
  created() {
    this.id = this.$route.query.id;
    this.getMemberInfo();
  },
  methods: {
    getMemberInfo() {
      queryMemberById({ id: this.id }).then(res => {
        if (!res.data.errCode) {
          this.form = res.data.userUserinfo;
          this.platformList = res.data.platformList;
          this.hobbyInterest = res.data.hobbyInterest;
          this.hobbyRepast = res.data.hobbyRepast;
          this.channelList = res.data.channelList;
          this.sourceList = res.data.sourceList;
          console.log(this.platformList);
        }
      });
    },
    // 新增爱好
    add_hobbyInterest() {
      if (this.hobbyInterestIcon) {
        this.hobbyInterest.push(this.hobbyInterestIcon);
        this.hobbyInterestIcon = "";
      }
    },
    // 删除爱好
    remove_hobbyInterest(i) {
      console.log(i);
      this.hobbyInterest.forEach((item, index) => {
        if (i === index) {
          this.hobbyInterest.splice(index, 1);
        }
      });
    },
    // 编辑爱好
    edit_hobbyInterest(i) {
      this.witchHobby = true;
      this.dialogEdit = true;
      this.witchIndex = i;
      this.hobbyInterest.forEach((item, index) => {
        if (i === index) {
          this.editIcon = item;
        }
      });
    },
    editSure() {
      if (this.witchHobby) {
        this.hobbyInterest[this.witchIndex] = this.editIcon;
      } else {
        this.hobbyRepast[this.witchIndex] = this.editIcon;
      }
      this.dialogEdit = false;
    },
    // 新增餐饮爱好
    add_hobbyRepast() {
      console.log(this.hobbyRepastIcon);
      if (this.hobbyRepastIcon) {
        this.hobbyRepast.push(this.hobbyRepastIcon);
        this.hobbyRepastIcon = "";
      }
    },
    // 编辑餐饮爱好
    edit_hobbyRepast(i) {
      this.witchHobby = false;
      this.dialogEdit = true;
      this.witchIndex = i;
      this.hobbyRepast.forEach((item, index) => {
        if (i === index) {
          this.editIcon = item;
        }
      });
    },
    // 删除餐饮爱好
    remove_hobbyRepast(i) {
      this.hobbyRepast.forEach((item, index) => {
        if (i === index) {
          this.hobbyRepast.splice(index, 1);
        }
      });
    },
    // 提交
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.form.hobbyInterest = this.hobbyInterest.join(";");
          this.form.hobbyRepast = this.hobbyRepast.join(";");
          console.log(this.form);
          updateMember(this.form).then(res => {
            if (!res.data.errCode) {
              this.$message({
                message: "会员信息更新成功",
                type: "success"
              });
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    back() {
      this.$router.back();
    }
  },
  components: {
    Breadcrumb
  }
};
</script>
<style lang="scss">
.add {
  .add-input {
    width: 92%;
  }
  .hobby-list {
    display: flex;
    margin-top: 10px;
    flex-wrap: wrap;
    li {
      width: 29%;
      padding: 0 10px;
      border: 1px solid #ddd;
      height: 30px;
      font-size: 12px;
      line-height: 30px;
      border-radius: 3px;
      margin-right: 1%;
      margin-bottom: 10px;
      &:nth-child(3n) {
        margin-right: 0;
      }
      .fa {
        line-height: 30px;
        margin-right: 15px;
        cursor: pointer;
        &:hover {
          color: #6d2377;
        }
      }
    }
  }
  .add-btn {
    width: 8%;
    display: inline-block;
    text-align: center;
    height: 34px;
    font-size: 12px;
    line-height: 34px;
    background: #6d2377;
    color: #fff;
    border-radius: 0 3px 3px 0;
    cursor: pointer;
  }
}
</style>
